/*
 * defs.h
 *
 *  Created on: 2011-12-17
 *      Author: Haifeng
 */

#ifndef _DEFS_H_
#define _DEFS_H_

#include <stdio.h>

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifndef TRUE
#define TRUE  1
#define FALSE 0
#endif

typedef char BOOL;
typedef unsigned int UINT;
typedef unsigned long DWORD;

#define CONTAINER_OF(ptr, type, member) \
		((type *)((char *)(ptr) - (unsigned long)&((type *)0)->member))

#define SET_FLAGS(var, flags)   do { (var) |= (flags); } while(0)
#define UNSET_FLAGS(var, flags) do { (var) &= ~(flags); } while(0)
#define ISSET_FLAGS(var, flags) ((var) & (flags) == (flags))

#define SRAND(x)  (srand(x))
#define SRAND_NOW (srand(time(NULL)))
#define RAND_INT  (rand())

static inline void *awl_alloc(size_t size) {
	void *ptr = malloc(size);
//	printf("## awl_alloc %p (%u)\n", ptr, size);
	return ptr;
};

static inline void awl_free(void *ptr) {
//	printf("## awl_free %p\n", ptr);
	free(ptr);
};

#endif /* _DEFS_H_ */
